﻿using System;
using NUnit.Framework;
using Omu.Encrypto;

namespace Tests
{
    [TestFixture]
    public class HasherTests
    {
        [Test]
        public void EncryptWithSaltTest()
        {
            const string original = "hello";

            //by default salt size is 4
            var h = new Hasher { SaltSize = 10 };
            var s = h.Encrypt(original);
            var s2 = h.Encrypt(original);
            Console.WriteLine(s);
            Console.WriteLine(s2);

            Assert.AreNotEqual(original, s);
            Assert.AreNotEqual(original, s2);
            Assert.AreNotEqual(s, s2);

            Assert.IsTrue(h.CompareStringToHash(original, s));
            Assert.IsTrue(h.CompareStringToHash(original, s2));
        }
        
        [Test]
        public void EncryptWithoutSaltTest()
        {
            const string original = "hello";
            var h = new Hasher { SaltSize = 0 };
            var s = h.Encrypt(original);
            var s2 = h.Encrypt(original);
            Console.WriteLine(s);
            Console.WriteLine(s2);

            Assert.AreNotEqual(original, s);
            Assert.AreNotEqual(original, s2);
            Assert.AreEqual(s, s2);

            Assert.IsTrue(h.CompareStringToHash(original, s));
            Assert.IsTrue(h.CompareStringToHash(original, s2));
        }
    }
}
